<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of pickup
 * 
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Pickup extends MY_Controller {

    //put your code here


    function pickup() {
        parent :: __construct();+
        $this->load->model('pickup_model');
        $this->template->set_theme('admin');
        $this->template->set_layout('admin_layout');
        $this->commoncall->check_admin_login();
        
    }

    function index() {
        $data['pickup_code'] = $this->pickup_model->get_pickup_codes();
        $this->template->title('Dashboard', $this->settings_model->get_setting('webtitle'))
                ->set_partial('admin_header', 'header/admin_header')
                ->set_partial('admin_left_menu', 'sidebar/admin_left_menu')
                ->build('pages/admin_pickup_code',$data);
       
    }

    function pickup_code_submit() {
        $this->form_validation->set_rules('pickup_code_description', 'Description', 'trim|required|is_unique[pickup.description]');
        if ($this->form_validation->run() == FALSE) {
            $this->session->set_flashdata('message', 'Error! Invalid Operation');
            $data['pickup_code'] = $this->pickup_model->get_pickup_codes();
            $this->load->view('admin/admin_pickup_code', $data);
        } else {
            $post_data = array(
                'code' => $this->pickup_model->get_max_pickup_no('CODE',0),
                'description' => $_POST['pickup_code_description']
            );
            $this->pickup_model->pickup_code_insert($post_data);
            $this->session->set_flashdata('message', 'Added Successfully');
            redirect('admin/pickup');
        }
    }
    
    function pickup_code_delete($code){
        $this->pickup_model->pickup_code_delete($code);
        redirect('admin/pickup');
    }
    
    function pickup_description_delete($code,$slno){
        $this->pickup_model->pickup_description_delete($code,$slno);
        $this->pickup_detail($code);
    }

//--Pickup Main Code update Subha(01/08/2012)--->        
    function pickup_code_update(){
        $this->form_validation->set_rules('description', 'Description', 'trim|required|is_unique[pickup.description]');
        if ($this->form_validation->run() == TRUE) {
            $post_data = array(
                'id' => $_POST['id'],
                'description' => $_POST['description']
            );
            $this->pickup_model->pickup_code_update($post_data);
        }
        redirect('admin/pickup');
    }

//--Pickup Description update Subha(01/08/2012)--->    
    function pickup_description_update(){
        $this->form_validation->set_rules('description', 'Description', 'trim|required|is_unique[pickup.description]');
        if ($this->form_validation->run() == TRUE) {
            $post_data = array(
                'code' => $_POST['code'],
                'slno' => $_POST['slno'],
                'description' => $_POST['description']
            );
            $this->pickup_model->pickup_description_update($post_data);
        }
        redirect('admin/pickup/pickup_detail/'.$_POST['code']);
    }

//--Get Pickup Detail -->
    function pickup_detail($code){
        if($code){
            $data['pickup_detail'] = $this->pickup_model->get_pickup($code);
            $data['pickup']['info'] = $this->pickup_model->get_pickup_info($code,0);
            $this->template->title('Dashboard', $this->settings_model->get_setting('webtitle'))
                ->set_partial('admin_header', 'header/admin_header')
                ->set_partial('admin_left_menu', 'sidebar/admin_left_menu')
                ->build('pages/admin_pickup_detail',$data);
           
        }
    }
    
//--Add New Pickup Detail --//
    function pickup_detail_submit(){
        $this->form_validation->set_rules('pickup_description', 'Description', 'trim|required|is_unique[pickup.description]');
        $this->form_validation->set_rules('pickup_code', 'Description', 'trim|required');
        if ($this->form_validation->run() == FALSE) {
            $this->session->set_flashdata('message', 'Error! Invalid Operation');
        }else{
           $post_data = array(
                'code' => $_POST['pickup_code'],
                'slno' => $this->pickup_model->get_max_pickup_no('SLNO',$_POST['pickup_code']),
                'description' => $_POST['pickup_description']
            );
            $this->pickup_model->pickup_detail_insert($post_data);
            $this->session->set_flashdata('message', 'Added Successfully');
        }
        $this->pickup_detail($_POST['pickup_code']);
    }
    
    
    
    
}
?>
